<template>
  <el-form ref="form" :model="model" :rules="rules" label-position="left" label-width="100px">
    <el-form-item label="用户名" prop="name">
      <el-input v-model="model.name" placeholder="请输入用户名"></el-input>
    </el-form-item>
    <!-- <el-form-item label="昵称">
      <el-input v-model="model.nickName" placeholder="请输入昵称"></el-input>
    </el-form-item> -->
    <el-form-item label="手机号" prop="phone">
      <el-input v-model="model.phone" placeholder="请输入手机号"></el-input>
    </el-form-item>
    <el-form-item label="邮箱" prop="email">
      <el-input v-model="model.email" placeholder="请输入邮箱"></el-input>
    </el-form-item>
    <!-- <el-form-item label="工号" prop="jobNum">
      <el-input v-model="model.jobNum" placeholder="请输入工号"></el-input>
    </el-form-item> -->
    <el-form-item label="所属公司" v-if="$store.state.userinfo.type === 0">
      <el-select v-model="model.companyId" placeholder="请选择所属公司">
        <el-option v-for="company in $store.state.company" :key="company.id" :label="company.companyName" :value="company.id"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="角色">
      <el-select v-model="model.roleList" multiple placeholder="请选择角色(可多选)">
        <el-option v-for="role in $store.state.companyroles" :key="role.id" :label="role.name" :value="role.id"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="账户类型" v-if="$store.state.userinfo.type === 0">
      <el-select v-model="model.type" placeholder="请选择账户类型">
        <el-option v-for="type in $store.state.acounttype" :key="type.value" :label="type.key" :value="type.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="密码" prop="password" v-if="!isEdit">
      <el-input type="password" v-model="model.password" placeholder="请输入密码"></el-input>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: 'UserForm',
  props: {
    model: {
      type: Object,
      required: true
    },
    rules: {
      type: Object,
      required: true
    },
    acountType: {
      type: Number,
      required: false,
      default: 1
    },
    isEdit: {
      type: Boolean,
      required: true
    }
  },
  created() {
    this.role = this.roleChecked
    this.type = this.acountType
  },
  methods: {
    validate() {
      let _valid
      this.$refs.form.validate(valid => {
        if (valid) _valid = valid
      })
      return _valid
    },
    resetFields() {
      this.$refs.form.resetFields()
    }
  }
}
</script>

<style></style>
